-- redis_test.lua
import("db/redis_mgr.lua")

local log_debug = logger.debug

local timer_mgr = quanta.get("timer_mgr")
local redis_mgr = quanta.get("redis_mgr")

timer_mgr:once(2000, function()
    local code, res = redis_mgr:execute("get", "aaa")
    log_debug("db get code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("set", "aaa", {abc = 3, ddd = 4})
    log_debug("db set code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("get", "aaa")
    log_debug("db get code: {}, res = {}", code, res)

    code, res = redis_mgr:execute("get", "aaa")
    log_debug("db get code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("hget", "bb", "k1")
    log_debug("db hget code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("hset", "bb", "k1", 123)
    log_debug("db hset code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("hmset", "bb", "k2", 234, "k3", 345)
    log_debug("db hmset code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("hget", "bb", "k1")
    log_debug("db hget code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("hdel", "bb", "k1")
    log_debug("db hdel code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("hmget", "bb", "k1", "k2", "k3")
    log_debug("db hget code: {}, res = {}", code, res)
    local scode, cur, vals  = redis_mgr:execute("hscan", "bb", 0)
    log_debug("db hscan code: {}, cur = {}, vals={}", scode, cur, vals)
    code, res = redis_mgr:execute("sadd", "sset", "k1", "k2", "k3")
    log_debug("db sadd code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("scard", "sset")
    log_debug("db scard code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("sismember", "sset", "one")
    log_debug("db sismember code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("sismember", "sset", "k2")
    log_debug("db sismember code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("smembers", "sset")
    log_debug("db smembers code: {}, res = {}", code, res)
    scode, cur, vals  = redis_mgr:execute("sscan", "sset", 0)
    log_debug("db sscan code: {}, cur = {}, vals={}", scode, cur, vals)
    code, res = redis_mgr:execute("spop", "sset")
    log_debug("db spop code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("zadd", "zset1",1,"one")
    log_debug("db zadd code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("zadd", "zset1",1,"uno")
    log_debug("db zadd code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("zadd", "zset1",2,"two")
    log_debug("db zadd code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("zadd", "zset1",3,"three")
    log_debug("db zadd code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("zcard", "zset1")
    log_debug("db zcard code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("zcount", "zset1",1,2)
    log_debug("db zcount code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("zrange", "zset1",0,2)
    log_debug("db zrange code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("zrank", "zset1","two")
    log_debug("db zrank code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("zscore", "zset1","two")
    log_debug("db zscore code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("zrange", "zset1", 0, 2, "WITHSCORES")
    log_debug("db zrange withscores code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("zrangebyscore", "zset1", 0, 2)
    log_debug("db zrange zrangebyscore code: {}, res = {}", code, res)
    scode, cur, vals  = redis_mgr:execute("zscan", "zset1", 0)
    log_debug("db zscan code: {}, cur = {}, vals={}", scode, cur, vals)
    --[[
    --code, res = redis_mgr:execute("subscribe", "test")
    --log_debug("db subscribe code: {}, res = {}", code, res)
    code, res = redis_mgr:execute("publish", "test", 123)
    log_debug("db publish code: {}, res = {}", code, res)
    log_debug("db spop code: {}, res = {}", code, res)
    ]]
end)